<?php

class ListPetAction extends CAction
{
	const PAGE_SIZE=3;

	public function run()
	{
		$criteria=new CDbCriteria;
		$criteria->condition='userName=:userName';
		$criteria->params=array(':userName'=>Yii::app()->user->name);

		$pages=new CPagination(Pet::countPet($criteria));
		$pages->pageSize=self::PAGE_SIZE;
		$pages->applyLimit($criteria);

		$petList=Pet::ListPet($criteria);
		if(empty($petList))
			throw new CHttpException(500, 'cannot find any pet for user['.Yii::app()->user->name.']');

		$this->getController()->render('ListPet',array(
			'petList'=>$petList,
			'pages'=>$pages,
		));
	}
}

?>
